package com.link.common.util;

import java.net.InetAddress;

public final  class NetUtils {

    public static  short testNetDelay(String host){
        int timeout = 5000; // 超时时间（毫秒）

        try {
            InetAddress address = InetAddress.getByName(host);
            long startTime = System.currentTimeMillis();
            boolean reachable = address.isReachable(timeout);
            long endTime = System.currentTimeMillis();

            if (reachable) {
                long latency = endTime - startTime;

                return (short) latency;
            }
        }catch ( Exception e){
            System.out.println(e.getMessage());
            return 9999;
        }
        return 9999;
    }
}
